﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Terraria.Graphics.Shaders
{
	// Token: 0x02000391 RID: 913
	public class ScreenShaderData : ShaderData
	{
		// Token: 0x1700022A RID: 554
		// (get) Token: 0x0600203C RID: 8252 RVA: 0x00016B1C File Offset: 0x00014D1C
		public float Intensity
		{
			get
			{
				return this._uIntensity;
			}
		}

		// Token: 0x1700022B RID: 555
		// (get) Token: 0x0600203D RID: 8253 RVA: 0x00016B24 File Offset: 0x00014D24
		public float CombinedOpacity
		{
			get
			{
				return this._uOpacity * this._globalOpacity;
			}
		}

		// Token: 0x0600203E RID: 8254 RVA: 0x0045BBA8 File Offset: 0x00459DA8
		public ScreenShaderData(string passName) : base(Main.ScreenShaderRef, passName)
		{
		}

		// Token: 0x0600203F RID: 8255 RVA: 0x0045BC6C File Offset: 0x00459E6C
		public ScreenShaderData(Ref<Effect> shader, string passName) : base(shader, passName)
		{
		}

		// Token: 0x06002040 RID: 8256 RVA: 0x00006B58 File Offset: 0x00004D58
		public virtual void Update(GameTime gameTime)
		{
		}

		// Token: 0x06002041 RID: 8257 RVA: 0x0045BD2C File Offset: 0x00459F2C
		public new virtual void Apply()
		{
			Vector2 value = new Vector2((float)Main.offScreenRange, (float)Main.offScreenRange);
			Vector2 value2 = new Vector2((float)Main.screenWidth, (float)Main.screenHeight) / Main.GameViewMatrix.Zoom;
			Vector2 value3 = new Vector2((float)Main.screenWidth, (float)Main.screenHeight) * 0.5f;
			Vector2 value4 = Main.screenPosition + value3 * (Vector2.One - Vector2.One / Main.GameViewMatrix.Zoom);
			base.Shader.Parameters["uColor"].SetValue(this._uColor);
			base.Shader.Parameters["uOpacity"].SetValue(this.CombinedOpacity);
			base.Shader.Parameters["uSecondaryColor"].SetValue(this._uSecondaryColor);
			base.Shader.Parameters["uTime"].SetValue(Main.GlobalTime);
			base.Shader.Parameters["uScreenResolution"].SetValue(value2);
			base.Shader.Parameters["uScreenPosition"].SetValue(value4 - value);
			base.Shader.Parameters["uTargetPosition"].SetValue(this._uTargetPosition - value);
			base.Shader.Parameters["uImageOffset"].SetValue(this._uImageOffset);
			base.Shader.Parameters["uIntensity"].SetValue(this._uIntensity);
			base.Shader.Parameters["uProgress"].SetValue(this._uProgress);
			base.Shader.Parameters["uDirection"].SetValue(this._uDirection);
			base.Shader.Parameters["uZoom"].SetValue(Main.GameViewMatrix.Zoom);
			for (int i = 0; i < this._uImages.Length; i++)
			{
				if (this._uImages[i] != null && this._uImages[i].Value != null)
				{
					Main.graphics.GraphicsDevice.Textures[i + 1] = this._uImages[i].Value;
					int width = this._uImages[i].Value.Width;
					int height = this._uImages[i].Value.Height;
					if (this._samplerStates[i] != null)
					{
						Main.graphics.GraphicsDevice.SamplerStates[i + 1] = this._samplerStates[i];
					}
					else if (Utils.IsPowerOfTwo(width) && Utils.IsPowerOfTwo(height))
					{
						Main.graphics.GraphicsDevice.SamplerStates[i + 1] = SamplerState.LinearWrap;
					}
					else
					{
						Main.graphics.GraphicsDevice.SamplerStates[i + 1] = SamplerState.AnisotropicClamp;
					}
					base.Shader.Parameters["uImageSize" + (i + 1)].SetValue(new Vector2((float)width, (float)height) * this._imageScales[i]);
				}
			}
			base.Apply();
		}

		// Token: 0x06002042 RID: 8258 RVA: 0x00016B33 File Offset: 0x00014D33
		public ScreenShaderData UseImageOffset(Vector2 offset)
		{
			this._uImageOffset = offset;
			return this;
		}

		// Token: 0x06002043 RID: 8259 RVA: 0x00016B3D File Offset: 0x00014D3D
		public ScreenShaderData UseIntensity(float intensity)
		{
			this._uIntensity = intensity;
			return this;
		}

		// Token: 0x06002044 RID: 8260 RVA: 0x00016B47 File Offset: 0x00014D47
		public ScreenShaderData UseColor(float r, float g, float b)
		{
			return this.UseColor(new Vector3(r, g, b));
		}

		// Token: 0x06002045 RID: 8261 RVA: 0x00016B57 File Offset: 0x00014D57
		public ScreenShaderData UseProgress(float progress)
		{
			this._uProgress = progress;
			return this;
		}

		// Token: 0x06002046 RID: 8262 RVA: 0x00016B61 File Offset: 0x00014D61
		public ScreenShaderData UseImage(Texture2D image, int index = 0, SamplerState samplerState = null)
		{
			this._samplerStates[index] = samplerState;
			if (this._uImages[index] == null)
			{
				this._uImages[index] = new Ref<Texture2D>(image);
			}
			else
			{
				this._uImages[index].Value = image;
			}
			return this;
		}

		// Token: 0x06002047 RID: 8263 RVA: 0x00016B95 File Offset: 0x00014D95
		public ScreenShaderData UseImage(string path, int index = 0, SamplerState samplerState = null)
		{
			this._uImages[index] = TextureManager.AsyncLoad(path);
			this._samplerStates[index] = samplerState;
			return this;
		}

		// Token: 0x06002048 RID: 8264 RVA: 0x00016BAF File Offset: 0x00014DAF
		public ScreenShaderData UseColor(Color color)
		{
			return this.UseColor(color.ToVector3());
		}

		// Token: 0x06002049 RID: 8265 RVA: 0x00016BBE File Offset: 0x00014DBE
		public ScreenShaderData UseColor(Vector3 color)
		{
			this._uColor = color;
			return this;
		}

		// Token: 0x0600204A RID: 8266 RVA: 0x00016BC8 File Offset: 0x00014DC8
		public ScreenShaderData UseDirection(Vector2 direction)
		{
			this._uDirection = direction;
			return this;
		}

		// Token: 0x0600204B RID: 8267 RVA: 0x00016BD2 File Offset: 0x00014DD2
		public ScreenShaderData UseGlobalOpacity(float opacity)
		{
			this._globalOpacity = opacity;
			return this;
		}

		// Token: 0x0600204C RID: 8268 RVA: 0x00016BDC File Offset: 0x00014DDC
		public ScreenShaderData UseTargetPosition(Vector2 position)
		{
			this._uTargetPosition = position;
			return this;
		}

		// Token: 0x0600204D RID: 8269 RVA: 0x00016BE6 File Offset: 0x00014DE6
		public ScreenShaderData UseSecondaryColor(float r, float g, float b)
		{
			return this.UseSecondaryColor(new Vector3(r, g, b));
		}

		// Token: 0x0600204E RID: 8270 RVA: 0x00016BF6 File Offset: 0x00014DF6
		public ScreenShaderData UseSecondaryColor(Color color)
		{
			return this.UseSecondaryColor(color.ToVector3());
		}

		// Token: 0x0600204F RID: 8271 RVA: 0x00016C05 File Offset: 0x00014E05
		public ScreenShaderData UseSecondaryColor(Vector3 color)
		{
			this._uSecondaryColor = color;
			return this;
		}

		// Token: 0x06002050 RID: 8272 RVA: 0x00016C0F File Offset: 0x00014E0F
		public ScreenShaderData UseOpacity(float opacity)
		{
			this._uOpacity = opacity;
			return this;
		}

		// Token: 0x06002051 RID: 8273 RVA: 0x00016C19 File Offset: 0x00014E19
		public ScreenShaderData UseImageScale(Vector2 scale, int index = 0)
		{
			this._imageScales[index] = scale;
			return this;
		}

		// Token: 0x06002052 RID: 8274 RVA: 0x0000EFC6 File Offset: 0x0000D1C6
		public virtual ScreenShaderData GetSecondaryShader(Player player)
		{
			return this;
		}

		// Token: 0x04003CEB RID: 15595
		private Vector3 _uColor = Vector3.One;

		// Token: 0x04003CEC RID: 15596
		private Vector3 _uSecondaryColor = Vector3.One;

		// Token: 0x04003CED RID: 15597
		private float _uOpacity = 1f;

		// Token: 0x04003CEE RID: 15598
		private float _globalOpacity = 1f;

		// Token: 0x04003CEF RID: 15599
		private float _uIntensity = 1f;

		// Token: 0x04003CF0 RID: 15600
		private Vector2 _uTargetPosition = Vector2.One;

		// Token: 0x04003CF1 RID: 15601
		private Vector2 _uDirection = new Vector2(0f, 1f);

		// Token: 0x04003CF2 RID: 15602
		private float _uProgress;

		// Token: 0x04003CF3 RID: 15603
		private Vector2 _uImageOffset = Vector2.Zero;

		// Token: 0x04003CF4 RID: 15604
		private Ref<Texture2D>[] _uImages = new Ref<Texture2D>[3];

		// Token: 0x04003CF5 RID: 15605
		private SamplerState[] _samplerStates = new SamplerState[3];

		// Token: 0x04003CF6 RID: 15606
		private Vector2[] _imageScales = new Vector2[]
		{
			Vector2.One,
			Vector2.One,
			Vector2.One
		};
	}
}
